<?php
namespace app\pay\controller;
use think\Controller;
use app\pay\service\Hqxe;
class Shoudong extends Controller
{
	public function huankuan(){//exit;
		//$mchid="425824232161";$bindid="BK6413203832";//李泽华 	440		742.1
		//$mchid="255818761363";$bindid="BK4311363562";//张建春 	444		737
		//$mchid="478376376165";$bindid="BK2318314648";//于汇洋	423		7.62	19051001582775762042343
//		$mchid="727310866088";$bindid="BK8778506227";//樊家辰 	429 	341.1
//		$mchid="580222761786";$bindid="BK6247343614";//张东阳 	437 	1053 19051012191311566042335
//		$mchid="050387270830";$bindid="BK4544842552";//陈东坡	421		161
//		$mchid="100555851158";$bindid="BK8024223827";//王小冬	463		0
//		$mchid="425824232161";$bindid="BK6413203832";//李泽华
		$mchid="205365011162";$bindid="BK2240150385";//462
		$balance = $this->queryBalance($mchid,$bindid);//halt($balance);
		if($balance["currAccountBalance"]>1){
			return $this->withDraw($mchid,$bindid,$balance["currAccountBalance"]);
		}else{
			return json($balance);
		}
	}

	public function withDraw($mchid,$bindid,$money)
	{
		$data = [
			"ordersn" => get_order_sn("", "423"),//流水号
			"dsorderid" => get_order_sn("", "423"),//商户订单号
			"subMerchantNo" => $mchid,
			"bindId" => $bindid,
			"userFee" => 2*100,//交易手续费
			"amount" => ($money-2)*100,//金额
			"notifyUrl"=>'http://' . $_SERVER['HTTP_HOST'] . '/pay/Huidiao/index'
		];
		//halt($data);
		$res = (new Hqxe)->withDraw($data);
		return json($res);
	}

	public function queryBalance($mchid,$bindid)
	{
		$data = [
			"ordersn" => get_order_sn("", "423"),//流水号
			"dsorderid" => get_order_sn("", "423"),//商户订单号
			"subMerchantNo" => $mchid,
			"bindId" => $bindid,
		];
		$res = (new Hqxe)->queryBalance($data);
		return $res;
	}
}